package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-10-19 09:33
 **/
public class LeetCode383 {

    /**
     * 使用数组充当hash表的角色解决该题
     * @param ransomNote
     * @param magazine
     * @return
     */
    public boolean canConstruct(String ransomNote, String magazine) {
        //26个字母 letter:字母
        int[] letter = new int[26];
        int i = 0;
        for (; i < magazine.length(); i++) {
            letter[magazine.charAt(i) - 'a']++;
        }
        for (i = 0; i < ransomNote.length(); i++) {
            if (--letter[ransomNote.charAt(i) - 'a'] < 0) {
                return false;
            }
        }
        return true;
    }

}
